package co.yixiang.yshop.module.system.controller.admin.roleauthdata;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.common.util.object.BeanUtils;
import co.yixiang.yshop.module.system.controller.admin.roleauthdata.vo.*;
import co.yixiang.yshop.module.system.dal.dataobject.roleauthdata.SysRoleAuthDataDO;
import co.yixiang.yshop.module.system.service.roleauthdata.SysRoleAuthDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 角色权限数据")
@RestController
@RequestMapping("/system/role-auth-data")
@Validated
public class SysRoleAuthDataController {

    @Resource
    private SysRoleAuthDataService roleAuthDataService;

    @GetMapping("/list")
    @Operation(summary = "获得角色权限数据列表")
    public CommonResult<List<SysRoleAuthDataRespVO>> getRoleAuthDataList(@Valid SysRoleAuthDataPageReqVO pageReqVO) {
        List<SysRoleAuthDataDO> list = roleAuthDataService.getRoleAuthDataList(pageReqVO);
        return success(BeanUtils.toBean(list, SysRoleAuthDataRespVO.class));
    }

    @PostMapping("/saveRoleAuth")
    @Operation(summary = "保存用户权限数据")
    public CommonResult<Boolean> saveRoleAuthData(@Valid @RequestBody SysRoleAuthDataSaveReqVO reqVO) {
        roleAuthDataService.saveRoleAuthData(
                reqVO.getUserId(),
                reqVO.getStoreIds(),
                reqVO.getDataTypeId()
        );
        return success(true);
    }

} 